import type { RowType } from '#/views/onlineDesign/dataSource/dataSource.data';

import { requestClient } from '#/api/request';

export namespace OnlineDataSourceTableApi {
  export type RowTypeFetchParams = RowType;
  export interface IdFetchParams {
    id: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
  export interface PageListFetchParams {
    [key: string]: any;
    pageNo: number;
    pageSize: number;
  }
}

/**
 * 分页列表查询
 */
export async function onlineDataSourceQueryPageListApi(
  params: OnlineDataSourceTableApi.PageListFetchParams,
) {
  return requestClient.get('/online/dataSource/queryPageList', {
    params,
  });
}

/**
 * 列表查询
 */
export async function onlineDataSourceQueryListApi(
  params: OnlineDataSourceTableApi.ListFetchParams,
) {
  return requestClient.get('/online/dataSource/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function onlineDataSourceQueryByIdApi(
  params: OnlineDataSourceTableApi.IdFetchParams,
) {
  return requestClient.get('/online/dataSource/queryById', { params });
}

/**
 * 新增
 */
export async function onlineDataSourceAddApi(
  params: OnlineDataSourceTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/online/dataSource/add', params);
}

/**
 * 编辑
 */
export async function onlineDataSourceEditApi(
  params: OnlineDataSourceTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/online/dataSource/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function onlineDataSourceDelApi(id) {
  return requestClient.delete<boolean>(`/online/dataSource/delete/${id}`);
}

/**
 * 批量删除删除
 * @param ids 主键
 */
export async function onlineDataSourceDeleteBatchApi(ids) {
  return requestClient.delete<boolean>(
    `/online/dataSource/deleteBatchByIds/${ids}`,
  );
}

/**
 * 测试连接数据源
 * @param id 主键
 */
export async function onlineDataSourceTestConnectApi(id: string) {
  return requestClient.get<string>(`/online/dataSource/testConnect?id=${id}`);
}
